home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcr / pcr4_4.lha / DIST / gc / GChblkmap.c < prev    next >
C/C++ Source or Header  |  1990-04-19  |  3KB  |  113 lines

  1. /* begincopyright
  2.   Copyright (c) 1990 Xerox Corporation. All rights reserved.
  3.   Use and copying of this software and preparation of derivative works based
  4.   upon this software are permitted. Any distribution of this software or
  5.   derivative works must comply with all applicable United States export
  6.   control laws. This software is made available AS IS, and Xerox Corporation
  7.   makes no warranty about the software, its performance or its conformity to
  8.   any specification. Any person obtaining a copy of this software is requested
  9.   to send their name and post office or electronic mail address to:
  10.     PCR Coordinator
  11.     Xerox PARC
  12.     3333 Coyote Hill Rd.
  13.     Palo Alto, CA 94304
  14.     
  15.   endcopyright */
  16.   
  17. /* Routines for maintaining a cache of maps describing heap block
  18.  * layouts for various object sizes.  Allows fast pointer validity checks
  19.  * and fast location of object start locations on machines (such as SPARC)
  20.  * with slow division.
  21.  *
  22.  * Boehm, March 9, 1990 10:22:45 am PST
  23.  */
  24.  
  25. # include "xr/GCPrivate.h"
  26.  
  27. void GC_flush_map_cache()
  28. {
  29.     register int i;
  30.     
  31.     for (i = 0; i < MAXOBJSZ + 1; i++) {
  32.         obj_map[i] = 0;
  33.     }
  34. #   ifdef PRINTSTATS
  35.     GC_printf("Flushed block map cache\n");
  36. #   endif    
  37.     GC_n_maps_cached = 0;
  38. }               
  39.  
  40. # ifdef RESTRICTED_INTERIOR_POINTERS
  41.  
  42. /* Consider pointers that are offset bytes displaced from the beginning */
  43. /* of an object to be valid.                            */
  44. void GC_register_displacement(offset) 
  45. long offset;
  46. {
  47.     if (offset > MAX_OFFSET) {
  48.         GC_abort("Bad argument to GC_register_displacement");
  49.     }
  50.     if (!valid_offsets[offset]) {
  51.       valid_offsets[offset] = TRUE;
  52.       GC_flush_map_cache();
  53.     }
  54. }
  55.  
  56. /* Is there any valid byte offset that can be truncated to the given */
  57. /* word offset?                                 */
  58. static bool valid_word_offset(word_offset)
  59. long word_offset;
  60. {
  61.     return(
  62.         valid_offsets[WORDS_TO_BYTES(word_offset)]
  63.         || valid_offsets[WORDS_TO_BYTES(word_offset) + 1]
  64.         || valid_offsets[WORDS_TO_BYTES(word_offset) + 2]
  65.         || valid_offsets[WORDS_TO_BYTES(word_offset) + 3]
  66.     );
  67. }
  68.  
  69. # endif
  70.  
  71. /* Try to add a heap block map for objects of size sz to the cache.  */
  72. void GC_add_cache_entry(sz)
  73. long sz;
  74. {
  75.     register int word_no;
  76.     register int offset;
  77.     register char * cache_entry;
  78.     
  79.     if (sz > MAXOBJSZ || GC_n_maps_cached == MAP_CACHE_SZ
  80.         || obj_map[sz] != (char *)0) {
  81.         return;
  82.     }
  83. #   ifdef INTERIOR_POINTERS
  84.     if (sz >= OBJ_INVALID) {
  85.         return;
  86.     }
  87. #   endif
  88. #   ifdef PRINTSTATS
  89.     GC_printf("Adding block map for size %d\n", sz);
  90. #   endif
  91.     cache_entry = map_cache[GC_n_maps_cached];
  92.     GC_n_maps_cached++;
  93.     for (word_no = HDR_WORDS; word_no + sz <= HBLKSIZE/BYTES_PER_WORD;
  94.          word_no += sz) {
  95.         cache_entry[word_no] = 0;
  96.         for (offset = 0; offset < sz; offset++) {
  97. #      ifdef INTERIOR_POINTERS
  98. #        ifdef RESTRICTED_INTERIOR_POINTERS
  99.         cache_entry[word_no + offset] =
  100.               (valid_word_offset(offset) ? offset : OBJ_INVALID);
  101. #        else
  102.         cache_entry[word_no + offset] = offset;
  103. #        endif
  104. #      else
  105.         cache_entry[word_no + offset] = (offset == 0 ? 0 : OBJ_INVALID);
  106. #      endif
  107.         }
  108.     }
  109.     for (; word_no < HBLKSIZE/BYTES_PER_WORD; word_no++) {
  110.         cache_entry[word_no] = OBJ_INVALID;
  111.     }
  112.     obj_map[sz] = cache_entry;
  113. }